﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ChoJuRating.UcControl
{
    /// <summary>
    /// UcKeyboard.xaml 的交互逻辑
    /// </summary>
    public partial class KeyboardView : Window
    {
        public string Result { get; private set; }

        private bool _isUp = true;

        public KeyboardView(string value = null)
        {
            InitializeComponent();

            tbkContent.Text = value;
            Result = value;

            grdLetterUp.Visibility = Visibility.Collapsed;
            grdLetterLow.Visibility = Visibility.Collapsed;
            btnSureNext.Visibility = Visibility.Visible;
            btnUpLow.Visibility = Visibility.Collapsed;
            btnUpLow.Content = "小写";
            bordFlod.Source = new BitmapImage(new Uri("pack://application:,,,/Public.ResourceBase;component/images/ico/floded.png"));
            this.Width = 500;
        }

        private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Point p = Mouse.GetPosition(this);
            if (p.Y <= 60 & e.LeftButton == MouseButtonState.Pressed)
                this.DragMove();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.Button btn = (System.Windows.Controls.Button)sender;
            var content = btn.Content;

            tbkContent.Text += _isUp ? content.ToString().ToUpper() : content.ToString().ToLower();
            Result = tbkContent.Text;
        }

        private void btnColse_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (tbkContent.Text.Length == 0)
                return;

            tbkContent.Text = tbkContent.Text.Substring(0, tbkContent.Text.Length - 1);
        }

        private void btnSure_Click(object sender, RoutedEventArgs e)
        {
            Result = tbkContent.Text;
            this.DialogResult = true;
        }

        private void btnFlod_Click(object sender, RoutedEventArgs e)
        {
            if (grdLetterUp.Visibility == Visibility.Collapsed)
            {
                grdLetterUp.Visibility = Visibility.Visible;
                grdLetterLow.Visibility = Visibility.Collapsed;
                btnSureNext.Visibility = Visibility.Collapsed;
                bordFlod.Source = new BitmapImage(new Uri("pack://application:,,,/Public.ResourceBase;component/images/ico/flod.png"));
                this.Width = 1330;
                btnUpLow.Visibility = Visibility.Visible;
            }
            else
            {
                grdLetterUp.Visibility = Visibility.Collapsed;
                grdLetterLow.Visibility = Visibility.Collapsed;
                btnSureNext.Visibility = Visibility.Visible;
                bordFlod.Source = new BitmapImage(new Uri("pack://application:,,,/Public.ResourceBase;component/images/ico/floded.png"));
                this.Width = 500;
                btnUpLow.Visibility = Visibility.Collapsed;
            }
        }

        private void btnUpLow_Click(object sender, RoutedEventArgs e)
        {
            _isUp = !_isUp;
            if(_isUp == true)
            {
                grdLetterUp.Visibility = Visibility.Visible;
                grdLetterLow.Visibility = Visibility.Collapsed;
                btnUpLow.Content = "小写";
            }
            else
            {
                grdLetterUp.Visibility = Visibility.Collapsed;
                grdLetterLow.Visibility = Visibility.Visible;
                btnUpLow.Content = "大写";
            }
        }
    }
}
